package com.laowang.project.system.controller;

import java.util.Date;
import java.util.List;

import com.laowang.common.utils.DateUtils;
import com.laowang.common.utils.MobileCheck;
import com.laowang.common.utils.StringUtils;
import com.laowang.project.pay.config.ReceiveOrderVo3;
import com.laowang.project.system.service.GZHPushMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.UserGroupApply;
import com.laowang.project.system.service.UserGroupApplyService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 俱乐部申请单Controller
 *
 * @author laowang
 * @date 2024-07-02
 */
@Api(tags = "俱乐部申请单接口")
@RestController
@RequestMapping("/groupApply")
public class UserGroupApplyController extends BaseController {
    @Autowired
    private UserGroupApplyService userGroupApplyService;

    @Autowired
    private GZHPushMessageService gzhPushMessageService;

    /**
     * 查询俱乐部申请单列表
     */
    @ApiOperation(value = "小程序端 申请俱乐部表单",notes = "")
    @PostMapping("/form")
    public AjaxResult form(@RequestBody UserGroupApply userGroupApply) {
        userGroupApply.setCreated(new Date());
        String phone = userGroupApply.getPhone();
        if (StringUtils.isEmpty(phone)){
            return AjaxResult.error("联系人手机号不能为空");
        }
        if (!MobileCheck.isMobile(phone)){
            return AjaxResult.error("手机号有误");
        }
        userGroupApplyService.insertUserGroupApply(userGroupApply);
        //发送微信公众号模版消息  陈岳安 湖南车友会公众号id
        ReceiveOrderVo3 receiveOrderVo3 = new ReceiveOrderVo3();
        receiveOrderVo3.setPhrase10(userGroupApply.getName());
        receiveOrderVo3.setPhone_number13(userGroupApply.getPhone());
        receiveOrderVo3.setThing2("申请俱乐部");
        String s = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date());
        receiveOrderVo3.setTime5(s);
        String openid = "oHnzZ6Pe8wqp2Q8TQ-spwInQCnDE";//我的 湖南车友会
        String openid1 = "oHnzZ6GCkvAFn6YL8eFptJFKP5Lk";//陈岳安
        //gzhPushMessageService.SendWxMsg3(openid1,receiveOrderVo3);
        return AjaxResult.success();
    }


    /**
     * 查询俱乐部申请单列表
     */
    @ApiOperation(value = "查询俱乐部申请单列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:groupApply:list')")
    @GetMapping("/list")
        public TableDataInfo list(UserGroupApply userGroupApply) {
        startPage();
        List<UserGroupApply> list = userGroupApplyService.selectUserGroupApplyList(userGroupApply);
        return getDataTable(list);
    }

    /**
     * 导出俱乐部申请单列表
     */
    @ApiOperation(value = "导出俱乐部申请单列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:groupApply:export')")
    @Log(title = "俱乐部申请单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserGroupApply userGroupApply) {
        List<UserGroupApply> list = userGroupApplyService.selectUserGroupApplyList(userGroupApply);
        ExcelUtil<UserGroupApply> util = new ExcelUtil<UserGroupApply>(UserGroupApply.class);
        return util.exportExcel(list, "groupApply");
    }

    /**
     * 获取俱乐部申请单详细信息
     */
    @ApiOperation(value = "获取俱乐部申请单详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:groupApply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(userGroupApplyService.selectUserGroupApplyById(id));
    }

    /**
     * 新增俱乐部申请单
     */
    @ApiOperation(value = "新增俱乐部申请单",notes = "")
    @PreAuthorize("@ss.hasPermi('my:groupApply:add')")
    @Log(title = "俱乐部申请单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserGroupApply userGroupApply) {
        return toAjax(userGroupApplyService.insertUserGroupApply(userGroupApply));
    }

    /**
     * 修改俱乐部申请单
     */
    @ApiOperation(value = "修改俱乐部申请单",notes = "")
    @PreAuthorize("@ss.hasPermi('my:groupApply:edit')")
    @Log(title = "俱乐部申请单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserGroupApply userGroupApply) {
        return toAjax(userGroupApplyService.updateUserGroupApply(userGroupApply));
    }

    /**
     * 删除俱乐部申请单
     */
    @ApiOperation(value = "删除俱乐部申请单",notes = "")
    @PreAuthorize("@ss.hasPermi('my:groupApply:remove')")
    @Log(title = "俱乐部申请单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(userGroupApplyService.deleteUserGroupApplyByIds(ids));
    }
}
